Algorithm Design and Problem-solving
100 questions· page 1 of 10
An identifier table has been used during the design stage.
Complete the identifier table:
| Example value | Explanation | Variable name | Data type |
|---|---|---|---|
| "Fruit" | a category of stock that is sold in the shop | ||
| 20/02/2025 | when an item was sold | ||
| 12.67 | the cost of an item | ||
| TRUE | to indicate if an item is in stock |
A module Sales() is part of the stock control program.
The table contains pseudocode extracts from the module Sales()
Each extract may include all or part of:
- assignment
- selection
- iteration (repetition).
Complete the table by placing one or more ticks (✓) in each row:
| Pseudocode extract | Assignment | Selection | Iteration |
|---|---|---|---|
Result ← CalculateTotal() | |||
WHILE IsClosed | |||
REPEAT INPUT Value UNTIL Sales[4] > Value | |||
IF Sales[Current] <= 150 THEN Discount ← TRUE ENDIF | |||
CASE OF Option |
Decomposition has been used to design the program to help the shop manager control the stock.
Describe decomposition.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
A student has been asked to create a simple guessing game program. This program will generate a random integer value between 1 and 100. It will then repeatedly prompt the user to input an integer value until they input the randomly generated value.
The student has written a structured English description:
step 1 – randomly generate an integer value between 1 and 100 inclusive
step 2 – prompt the user to input an integer value
step 3 – output an appropriate message if the value input was too high; then repeat from step 2
step 4 – output an appropriate message if the value input was too low; then repeat from step 2
step 5 – output an appropriate message if the value input was the same value that was randomly generated; then end the program.
Write a pseudocode algorithm from this structured English description.
Assume no input validation is needed.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
....................................................................................................................................................
An algorithm is designed to generate and output two unique random integers. Each integer value is between –10 and 10 inclusive.
If both integers output are negative, a third random integer between 30 and 35 inclusive will be generated and output.
Write pseudocode for this algorithm.
An algorithm will:
• input 100 integer values, one value at a time
• store the first value input into the first location of the array Number
• store the next input value in the next unused location of the array Number
• output the contents of Number array in the opposite sequence to that in which the values were input.
Complete the program flowchart to represent the algorithm.
Variable declarations are not required.
A programmer has been asked to create a module RollDice() to simulate multiple rolls of a dice. This module will be used as part of a program for a game.
The module will:
step 1 – take a positive integer parameter representing the number of times the dice will be rolled
step 2 – simulate one roll of the dice by generating a random integer between 1 and 6 inclusive
step 3 – output the integer generated
step 4 – repeat, as required from step 2
step 5 – calculate the average value of the random integers generated
step 6 – return the average value.
Write pseudocode for the module RollDice()
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
....................................................................................................................................................
Data is a global 1D array containing 30 elements of type STRING
An algorithm will output:
- all non-blank elements (elements that do not contain an empty string)
- the final total of the number of elements output.
Complete the program flowchart to represent the algorithm:
Data is a global 1D array containing 20 elements of type REAL
An algorithm will:
- input a sequence of real values, one at a time
- assign each value to consecutive array elements, starting from index 1
- end when the value 99.9 is input, or all 20 elements have been assigned (the value 99.9 must not be stored in the array).
Complete the program flowchart to represent the algorithm:
A string function Compare() will compare two strings.
The function will:
- take four parameters:
- two strings,
String1andString2 - a character,
Position, to indicate whetherString1will be compared with the start ('s'), or the end ('e') ofString2 - a Boolean,
CaseMatters, to indicate whether an upper case character and lower case character (for example,'A'and'a') are regarded as different (TRUE), or as the same (FALSE)
- two strings,
- return
FALSEifString2has fewer characters thanString1 - return
TRUEif the comparison is true, otherwise returnFALSE
For example:
| Parameter | Return value | |||
|---|---|---|---|---|
| String1 | String2 | CaseMatters | Position | |
"Cat" | "Catalogue" | TRUE | 's' | TRUE |
"CAT" | "Catalogue" | TRUE | 's' | FALSE |
"CAT" | "Catalogue" | FALSE | 's' | TRUE |
"Cat" | "Catalogue" | TRUE | 'e' | FALSE |
"GUE" | "Catalogue" | FALSE | 'e' | TRUE |
"Catalogue" | "Cat" | TRUE | 's' | FALSE |
Write pseudocode for the function Compare()
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
....................................................................................................................................................
Describe up to six steps for this algorithm that could be used to produce pseudocode.
Do not use pseudocode statements in your answer.
Step 1 .......................................................................................................................................
Step 2 .......................................................................................................................................
Step 3 .......................................................................................................................................
Step 4 .......................................................................................................................................
Step 5 .......................................................................................................................................
Step 6 .......................................................................................................................................
Iteration is one programming construct.
Identify one other programming construct that will be required when the algorithm from part (a) is converted into pseudocode and explain how it is used.
Construct ..................................................................................................................................
Use ...........................................................................................................................................
An algorithm for part of the program will:
- input three numeric values and assign them to identifiers
Num1,Num2andNum3 - assign the largest value to variable
Ans - output a message giving the largest value and the average of the three numeric values.
Assume the values are all different and are input in no particular order.
Complete the program flowchart on page 5 to represent the algorithm.
A different part of the program contains an algorithm represented by the following program flowchart:
Write pseudocode for the algorithm.